package ecmnext.utils;

/***************************************************************/
/*                     SOFTWARE SECTION                        */
/***************************************************************/
/*
 * <p>Name: ECMNext</p>
 * <p>Description: Simulation of the platform of trading Software</p>
 * <p>Licence: General Public License</p>
 * <p>Organisation: EC Marseille</p>
 * <p>Persons involved in the project : groupe Plateforme de Trading</p>
 * <p>Current version: 1.0</p>
 */


/***************************************************************/
/*                      IMPORT SECTION                         */
/***************************************************************/

import javax.swing.filechooser.*;

/***************************************************************/
/*                FileChooserFilter Class Section              */
/***************************************************************/
/**
 * <p>Title: FileChooserFilter</p>
 * <p>Description: filter for jFileChooser</p>
 * @author Xuewen YANG ET Antoine COUDERC
 * @version 0.2
 */

public class FileChooserFilter extends FileFilter {

  //Description et extension acceptee par le filtre
  private String description;
  private String extension;

  //Constructeur a partir de la description et de l'extension accepte
  public FileChooserFilter(String description, String extension){

    if(description == null || extension ==null){
      throw new NullPointerException("The description (or extension) should not be null.");
    }
   this.description = description;
   this.extension = extension;

  }

  //Implementation de FileFilter
  public boolean accept(java.io.File file){

    if(file.isDirectory()) {
      return true;
    }

    String nomFichier = file.getName().toLowerCase();
    return nomFichier.endsWith(extension);

  }

   public String getDescription(){
     return description;
   }

}
